<?php
session_start();
include_once("../../untils/conn.php");
mysqli_query($con, "set names utf8");

// 获取当前正在登录的账号信息的代理
$proxy_acc = $_SESSION["account"];

// 防止 SQL 注入攻击
$proxy_acc = mysqli_real_escape_string($con, $proxy_acc);

// 查询 withdrawal 表，根据 proxy_acc 来查找数据并将数据存储在数组中
$sql = "SELECT * FROM withdrawal WHERE proxy_acc = '$proxy_acc'";
$result = mysqli_query($con, $sql);
if ($result) {
    $data = array();

    // 循环遍历数据并将每条数据存储在一个数组中
    while ($row = mysqli_fetch_assoc($result)) {
        $proxy_acc = $row['proxy_acc'];
        $tx_name = $row['tx_name'];
        $tx_acc = $row['tx_acc'];
        $tx_type = $row['tx_type'];
        $tx_price = $row['tx_price'];
        $dk_price = $row['dk_price'];
        $tax = $row['tax'];
        $state = $row['state'];
        $cr_time = date('Y-m-d H:i:s', $row['cr_time']);
        $cl_time = date('Y-m-d H:i:s', $row['cl_time']);
        $tx_bank_name = $row['tx_bank_name'];
        $tx_bank_zh = $row['tx_bank_zh'];
        $notes = $row['notes'];

        $data[] = array(
            "proxy_acc" => $proxy_acc,
            "tx_name" => $tx_name,
            "tx_acc" => $tx_acc,
            "tx_type" => $tx_type,
            "tx_price" => $tx_price,
            "dk_price" => $dk_price,
            "tax" => $tax,
            "state" => $state,
            "cr_time" => $cr_time,
            "cl_time" => $cl_time,
            "tx_bank_name" => $tx_bank_name,
            "tx_bank_zh" => $tx_bank_zh,
            "notes" => $notes
        );
    }

    // 将数据转换为 JSON 格式并输出到前端
    echo json_encode($data);
}

// 关闭数据库连接
mysqli_close($con);
